package com.ibuonline.b2b.shop.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dimeng.common.base.BaseServiceImpl;
import com.ibuonline.b2b.entity.ShopColumn;
import com.ibuonline.b2b.entity.ShopColumnDef;
import com.ibuonline.b2b.shop.dao.ShopColumnDAO;
import com.ibuonline.b2b.shop.dao.ShopColumnDefDAO;

public class ShopColumnServiceImpl extends BaseServiceImpl<ShopColumn> implements ShopColumnService {

	private ShopColumnDefDAO shopColumnDefDAO;
	
	public List<ShopColumnDef> getAllShopColumnDef() {
		return shopColumnDefDAO.getAll("displayOrder");
	}

	public ShopColumnDefDAO getShopColumnDefDAO() {
		return shopColumnDefDAO;
	}

	public void setShopColumnDefDAO(ShopColumnDefDAO shopColumnDefDAO) {
		this.shopColumnDefDAO = shopColumnDefDAO;
	}

	public Map<Integer, List<ShopColumn>> getAllColumns(Integer companyId) {
		List<ShopColumn> columns = this.getByParam("companyId", companyId, "displayOrder");
		if (columns.size() == 0)
			return null;
		Map<Integer, List<ShopColumn>> map = new HashMap<Integer, List<ShopColumn>>(3);
		for (ShopColumn col : columns) {
			List<ShopColumn> list = map.get(col.getPosition());
			if (list == null) {
				list = new ArrayList<ShopColumn>();
				map.put(col.getPosition(), list);
			}
			list.add(col);
		}
		return map;
	}

	public void saveShopColumns(List<ShopColumn> shopColumns) {
		((ShopColumnDAO)dao).saveShopColumns(shopColumns);
	}

}
